import { defineStore } from 'pinia'
import { ref } from 'vue'
import { useGetInfoService } from '@/api/user'
export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const changeToken = (newToken) => {
      token.value = newToken
    }
    //用户基本信息
    const userinfo = ref('')
    const changeUserInfo = (newUserInfo) => {
      userinfo.value = newUserInfo
    }
    const getUserInfoService = async () => {
      const {
        data: { data }
      } = await useGetInfoService()
      userinfo.value = data
    }
    return {
      token,
      changeToken,
      userinfo,
      changeUserInfo,
      getUserInfoService
    }
  },
  {
    persist: true
  }
)
